
M = int(input())
N = int(input())
nums = []
for _ in range(M):
    infor = list(map(int,input().split()))
    nums.append(infor)

class unionfind():

    def __init__(self,n):
        self.nums = 0
        self.pre = list(range(n))
        for i in range(n):
            self.pre[i] = i
    def find(self,x):
        if self.pre[x] != x:
            self.pre[x]  = self.find(self.pre[x])
        return self.pre[x]
    def join(self,x,y):
        fx = self.find(x)
        fy = self.find(y)
        if fx != fy:
            self.pre[fy] = fx
            self.nums -= 1
    def add(self,x):
        self.nums += 1

Union = unionfind(M)
for i in range(M):
    Union.add(i)
    for j in range(i):
        if nums[i][j] == 0:
            Union.join(i,j)
res = Union.nums
print(res)
